home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Draw / TOvalObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-18  |  5.2 KB  |  212 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TOvalObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  20. ** on this function. */
  21.  
  22. /* This file implements the messages for the oval object.  Many of the messages
  23. ** can be handled by the rect object, as they deal with a rect structure.  Only
  24. ** a few of them are oval-specific. */
  25.  
  26. /* It would seem that you would want a custom hit-test message handler here, but
  27. ** the rect object first checks to see if the hit is within the bounding box of
  28. ** the object, and if so, it then calls the object to return the region.  This
  29. ** allows the rect object to generically handle hit-testing. */
  30.  
  31.  
  32.  
  33. /*****************************************************************************/
  34.  
  35.  
  36.  
  37. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  38. #include "App.protos.h"        /* Get the prototypes for the application.        */
  39.  
  40. #ifndef __OSEVENTS__
  41. #include <OSEvents.h>
  42. #endif
  43.  
  44. #ifndef __OSUTILS__
  45. #include <OSUtils.h>
  46. #endif
  47.  
  48. #ifndef __QUICKDRAW__
  49. #include <Quickdraw.h>
  50. #endif
  51.  
  52. #ifndef __STRING__
  53. #include <String.h>
  54. #endif
  55.  
  56. #ifndef __TREEOBJ2__
  57. #include "TreeObj2.h"
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. #pragma segment DrawObjects
  67. long    TOvalObj(TreeObjHndl hndl, short message, long data)
  68. {
  69.     Rect        rct;
  70.     RgnHandle    rgn;
  71.     short        h, w;
  72.     RGBColor    rgb, rgb2;
  73. #if VH_VERSION
  74.     char        *cptr;
  75. #endif
  76.  
  77.     switch (message) {
  78.         case INITMESSAGE:
  79.         case FREEMESSAGE:
  80.         case COPYMESSAGE:
  81.         case UNDOMESSAGE:
  82.         case CONVERTMESSAGE:
  83.         case FREADMESSAGE:
  84.         case FWRITEMESSAGE:
  85.         case HREADMESSAGE:
  86.         case HWRITEMESSAGE:
  87.         case HITTESTMESSAGE:
  88.         case GETOBJRECTMESSAGE:
  89.         case SETOBJRECTMESSAGE:
  90.         case SECTOBJRECTMESSAGE:
  91.         case GETBBOXMESSAGE:
  92.         case CLICKMESSAGE:
  93.         case KEYMESSAGE:
  94.         case SETSELECTMESSAGE:
  95.         case GETSELECTMESSAGE:
  96.         case SIZEMESSAGE:
  97.         case COMPAREMESSAGE:
  98.             return(TRectObj(hndl, message, data));
  99.             break;
  100.  
  101.         case GETRGNMESSAGE:
  102.             rgn = NewRgn();
  103.             OpenRgn();
  104.             rct = mDerefOval(hndl)->oval;
  105.             FrameOval(&rct);
  106.             CloseRgn(rgn);
  107.             return((long)rgn);
  108.             break;
  109.  
  110.         case DRAWMESSAGE:
  111.             rct = mDerefOval(hndl)->oval;
  112.             h   = mDerefCommon(hndl)->penHeight;
  113.             w   = mDerefCommon(hndl)->penWidth;
  114.             PenSize(w, h);
  115.             switch (data) {
  116.                 case DRAWOBJ:
  117.                     if (gQDVersion)
  118.                         GetForeColor(&rgb);
  119.                     ForeColor(whiteColor);
  120.                     if (gQDVersion) {
  121.                         rgb2 = mDerefLine(hndl)->contentColor;
  122.                         RGBForeColor(&rgb2);
  123.                     }
  124.                     PaintOval(&rct);
  125.                     ForeColor(blackColor);
  126.                     if (gQDVersion) {
  127.                         rgb2 = mDerefLine(hndl)->borderColor;
  128.                         RGBForeColor(&rgb2);
  129.                     }
  130.                     FrameOval(&rct);
  131.                     if (gQDVersion)
  132.                         RGBForeColor(&rgb);
  133.                     break;
  134.                 case ERASEOBJ:
  135.                     EraseOval(&rct);
  136.                     break;
  137.                 case DRAWSELECT:
  138.                     TRectObj(hndl, message, data);
  139.                     break;
  140.                 case DRAWGHOST:
  141.                     PenMode(patXor);
  142.                     FrameOval(&rct);
  143.                     break;
  144.                 case DRAWMASK:
  145.                     FillOval(&rct, (ConstPatternParam)&qd.black);
  146.                     break;
  147.             }
  148.             PenNormal();
  149.             break;
  150.  
  151.         case PRINTMESSAGE:
  152.             TOvalObj(hndl, DRAWMESSAGE, DRAWOBJ);
  153.             break;
  154.  
  155. #if VH_VERSION
  156.         case VHMESSAGE:
  157.             cptr = ((VHFormatDataPtr)data)->data;
  158.             ccatchr(cptr, 13, 2);
  159.             ccat   (cptr, "$10: TOvalObj:");
  160.             ccatchr(cptr, 13, 1);
  161.             ccat   (cptr, "  $00: selected     = ");
  162.             ccatdec(cptr, mDerefOval(hndl)->selected);
  163.             ccatchr(cptr, 13, 1);
  164.             rct = mDerefOval(hndl)->oval;
  165.             ccat   (cptr, "  $02: oval         = ($");
  166.             ccathex(cptr, 0, 4, 4, rct.top);
  167.             ccat   (cptr, ",$");
  168.             ccathex(cptr, 0, 4, 4, rct.left);
  169.             ccat   (cptr, ",$");
  170.             ccathex(cptr, 0, 4, 4, rct.bottom);
  171.             ccat   (cptr, ",$");
  172.             ccathex(cptr, 0, 4, 4, rct.right);
  173.             ccat   (cptr, ")");
  174.             ccatchr(cptr, 13, 1);
  175.             ccat   (cptr, "  $0A: penHeight    = ");
  176.             ccatdec(cptr, mDerefOval(hndl)->penHeight);
  177.             ccatchr(cptr, 13, 1);
  178.             ccat   (cptr, "  $0C: penWidth    = ");
  179.             ccatdec(cptr, mDerefOval(hndl)->penWidth);
  180.             ccatchr(cptr, 13, 1);
  181.             ccat   (cptr, "  $0E: borderColor  = ($");
  182.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.red);
  183.             ccat   (cptr, ",$");
  184.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.green);
  185.             ccat   (cptr, ",$");
  186.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->borderColor.blue);
  187.             ccat   (cptr, ")");
  188.             ccatchr(cptr, 13, 1);
  189.             ccat   (cptr, "  $1$: content      = ($");
  190.             ccatdec(cptr, mDerefOval(hndl)->content);
  191.             ccatchr(cptr, 13, 1);
  192.             ccat   (cptr, "  $16: contentColor = ($");
  193.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.red);
  194.             ccat   (cptr, ",$");
  195.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.green);
  196.             ccat   (cptr, ",$");
  197.             ccathex(cptr, 0, 4, 4, mDerefOval(hndl)->contentColor.blue);
  198.             ccat   (cptr, ")");
  199.             return(true);
  200.             break;
  201. #endif
  202.  
  203.         default:
  204.             break;
  205.     }
  206.  
  207.     return(noErr);
  208. }
  209.  
  210.  
  211.  
  212.